/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       animated_window.cpp

	$Header: /game/animated_window.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "animated_window.h"

#include "animation.h"
#include "bitmap_group.h"
#include "game_time.h"

// note: a "speed" of 100 uses the normal rate of animation, as specified in the resource.
// higher or lower numbers yield faster or slower animations.
t_animated_window::t_animated_window( t_animation_ptr const& bitmaps, t_screen_point point, 
									  int speed, t_window* parent )
	             : t_bitmap_group_window( t_bitmap_group_ptr( bitmaps ), point,
				                          bitmaps->get_frame_order()[0], parent )
{
	m_frame = 0;
	set_delay( bitmaps->get_frame_delay() * 100 / speed );
	m_start_frame = 0;
	m_frame_order = bitmaps->get_frame_order();
	m_end_frame = m_frame_order.size();
	m_cycle = true;
}

void t_animated_window::on_animation_end()
{
}

void t_animated_window::on_idle()
{
	if (!is_visible() || !is_open())
		return;

	m_frame++;
	if (m_frame >= m_end_frame)
	{
		if (!m_cycle)
		{
			t_counted_ptr<t_animated_window> ref = this;

			suspend_idle_processing();
			on_animation_end();
			m_end_handler( this );
			return;
		}
		m_frame = m_start_frame;
	}
	set_frame( m_frame );
}
